package com.lagou.edu.controller;

import com.lagou.edu.annotation.MySecurity;
import com.lagou.edu.pojo.Account;
import com.lagou.edu.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * AccountController
 *
 * @author Sinu
 * @Date ${DATE}
 */
@Controller
@RequestMapping("/account")
public class AccountController {

    /**
     * Spring容器和SpringMVC容器是有层次的（父子容器）
     * Spring容器：service对象+dao对象
     * SpringMVC容器：controller对象，，，，可以引用到Spring容器中的对象
     */


    @Autowired
    private AccountService accountService;

    /**
     * 测试：有配置 使用配置访问 通过
     * http://localhost:8080//account/queryAll1?username=zhangsan
     */
    @MySecurity(value = {"zhangsan"})
    @RequestMapping("/queryAll1")
    @ResponseBody
    public List<Account> queryAll1() throws Exception {
        return accountService.queryAccountList();
    }

    /**
     * 测试：有配置 使用配置访问 拒绝
     * http://localhost:8080//account/queryAll2?username=lisi
     */
    @MySecurity(value = {"zhangsan"})
    @RequestMapping("/queryAll2")
    @ResponseBody
    public List<Account> queryAll2() throws Exception {
        return accountService.queryAccountList();
    }

    /**
     * 测试：无配置 访问
     * http://localhost:8080//account/queryAll3
     */
    @MySecurity(value = {})
    @RequestMapping("/queryAll3")
    @ResponseBody
    public List<Account> queryAll3() throws Exception {
        return accountService.queryAccountList();
    }


}
